package courseselect.demoselect.web;

import courseselect.demoselect.entity.student;
import courseselect.demoselect.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Controller
public class showController {

    @Autowired
    private StudentMapper studentMapper;

    private student stu;

    @ModelAttribute(value = "zhangshang")
    public  student showStudent(){

     //这是一个修改的数据库访问测试   修改年级
        stu=studentMapper.getStudentByNumber(1);
        stu.setLevel(5);
        studentMapper.updataStudentLevel(stu);
        //————————
        return  studentMapper.getStudentByNumber(1);
    }

    @RequestMapping(value = "/show")
    public String over(HttpServletRequest request,Model model) {
       List<String>  selected=new ArrayList<>();
       selected= Arrays.asList(request.getParameterValues("category"));
       model.addAttribute("selected",selected);

      // student zhangshang=studentMapper.getStudentByNumber(1);

        String string1=String.join("-",selected);
      stu.setCourse(string1);


        System.out.println(stu);
       studentMapper.updataStudentCourse(stu);
      // String string1=String.join("-",selected);
        System.out.println(string1);
        return "show";
    }


}
